# $Id: debug.tcl 31 2007-08-25 00:50:31Z khomoutov $
# Simple debugging support

namespace eval ::dccore {
	variable debug_lvls [list]

	namespace export debug debugmsg
}

proc ::dccore::debug {op args} {
	switch -- $op {
		levels {
			variable debug_lvls
			if {[llength $args] > 1} {
				set debug_lvls [lsort $args]
			} else {
				set debug_lvls [lsort [lindex $args 0]]
			}
			set debug_lvls
		}
		default {
			return -code error "bad option \"$op\":\
				must be levels"
		}
	}
}

proc ::dccore::debugmsg {topic message} {
	variable debug_lvls

	if {([llength $debug_lvls] == 1
		&& [string equal [lindex $debug_lvls 0] *])
	|| [lsearch -sorted $debug_lvls $topic] >= 0} {
		puts $message
	}
}

